<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>web worker</title>
	</head>
	<body>
		<button id="startworker">start worker</button>
		<button id="stopworker">stop worker</button>
		<script>
			// 这一段代码是同步的
			var startworker = document.getElementById("startworker");
			var w;
			startworker.addEventListener("click",function(){
				if (typeof(Worker)!== undefined) {
					//可以使用 web worker
					w = new Worker("demo_worker.js")
					//调用w里面的各种方法
				} else{
					//提示用户web worker 
				}
			})
			
			var stopworker = document.getElementById("stopworker");
			stopworker.addEventListener("click",function(){
				//停止web worker
				w.terminate();
				w = undefined;
			})
		</script>
	</body>
</html>